package com.slt.concurrency.mashibing2019.juc.c_007_LockAndTools;

import java.util.concurrent.TimeUnit;
/**
 *  synchronized 也是可重入锁
 */
public class T01_ReentrantLock1 {
	synchronized void m1() {
		for(int i=0; i<10; i++) {
			try {
				TimeUnit.SECONDS.sleep(1);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println(i);
			//可重入
			if(i == 2){
				m2();
			}
		}
	}

	synchronized void m2() {
		System.out.println("m2 ...");
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		T01_ReentrantLock1 rl = new T01_ReentrantLock1();

		new Thread(rl::m1).start();
	}
}
